Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - [vb net 2013] If
Forum - C# / VB.NET - [vb net 2013] If

Avatar
ju89 (Normal User)
Pro


Messaggi: 61
Iscritto: 26/03/2014

Segnala al moderatore
Postato alle 17:36
Sabato, 26/04/2014
Eccomi qui di nuovo, sto impazzendo! Premetto che sto facendo un programma da autodidatta leggendo guide ed altro, però mi sono bloccato in un passaggio che sicuramente sarà una bella cavolata, ma a me sembra un masso! :D

Vi incollo il codice e poi ve lo spiego

Codice sorgente - presumibilmente VB.NET

  1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  2.         If sanzione.Text = "" Then
  3.             Return
  4.         ElseIf sanzione.Text >= 211 And sanzione.Text <= 2108 Then
  5.             sanzione12.Text = (sanzione.Text / 105).ToString("##")
  6.         ElseIf sanzione.Text >= 2108.01 And sanzione.Text <= 5270 Then
  7.             sanzione24.Text = (sanzione.Text / 105).ToString("##")
  8.         ElseIf sanzione.Text >= 5270.01 And sanzione.Text <= 99999.99 Then
  9.             sanzione60.Text = (sanzione.Text / 105).ToString("##")
  10.         End If
  11.         If sanzione12.Text >= 12 And sanzione12.Text < 24 Then
  12.             Label2.Text = 12
  13.         Else : Label2.Text = sanzione12.Text
  14.  
  15.         End If
  16.         If sanzione24.Text > 24 And sanzione24.Text < 60 Then
  17.             Label2.Text = 24
  18.         Else : Label2.Text = sanzione24.Text
  19.  
  20.         End If
  21.         If sanzione60.Text > 60 Then
  22.             Label2.Text = 60
  23.         Else : Label2.Text = sanzione60.Text
  24.         End If
  25.  
  26.     End Sub



Allora se inserisco un valore tra 211-2108 il risultato di (sanzione/105) me lo deve mettere nella textbox denominata sanzione12.text, se questo valore è maggiore di 12 allora deve scrivermi 12 sennò il risultato che esce nella sanzione12.text.
Stessa cosa vale per il valore inserito tra 2108.01 e 5270.00; il risultato di (sanzione/105) me lo deve mettere nella textbox denominata sanzione24.text e anche qui se il valore è maggiore di 24 allora deve scrivermi 24 sennò il risultato che esce nella sanzione24.text.
Stessa cosa vale per il valore tra 5270.01 e 99999.99 ma non mi dilungo a spiegare perchè tanto è uguale alle altre due.
Dove sbaglio?potete aiutarmi? Che tra l'altro qui non mi funziona il programma non mi fa nessun calcolo, solo se lascio :


Codice sorgente - presumibilmente VB.NET

  1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  2.         If sanzione.Text = "" Then
  3.             Return
  4.         ElseIf sanzione.Text >= 211 And sanzione.Text <= 2108 Then
  5.             sanzione12.Text = (sanzione.Text / 105).ToString("##")
  6.         ElseIf sanzione.Text >= 2108.01 And sanzione.Text <= 5270 Then
  7.             sanzione24.Text = (sanzione.Text / 105).ToString("##")
  8.         ElseIf sanzione.Text >= 5270.01 And sanzione.Text <= 99999.99 Then
  9.             sanzione60.Text = (sanzione.Text / 105).ToString("##")
  10.         End If
  11.         If sanzione12.Text >= 12 And sanzione12.Text < 24 Then
  12.             Label2.Text = 12
  13.         Else : Label2.Text = sanzione12.Text
  14.     End Sub



allora così il programma mi funziona. 8-|

PM Quote
Avatar
Ultimo (Member)
Guru


Messaggi: 877
Iscritto: 22/05/2010

Segnala al moderatore
Postato alle 21:47
Sabato, 26/04/2014
Codice sorgente - presumibilmente VB.NET

  1. Public Class Form1
  2.  
  3.     Const a As Byte = 1
  4.     Const b As Byte = 2
  5.     Const c As Byte = 3
  6.     Private f As Double
  7.  
  8.  
  9.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  10.  
  11.         Try
  12.             Dim nx As Double = CDbl(TextBox1.Text)
  13.             Call Esegui(nx)
  14.         Catch ex As Exception
  15.             MsgBox(ex.Message, MsgBoxStyle.Information)
  16.         End Try
  17.  
  18.     End Sub
  19.  
  20.     Private Sub Esegui(ByRef k As Double)
  21.         Try
  22.             Label1.Text = ""
  23.             If k > 100 And k < 1001 Then
  24.                 f = a * b * k
  25.             ElseIf k > 1000 Then
  26.                 f = k / (a * b)
  27.                 Label1.Text = " Diviso 2   "
  28.             Else : Label1.Text = " La sgniacchera  " & f.ToString("##")
  29.                 f = a * c * k
  30.                 Label1.Text &= "  e  La sgniacchera 2  : " & f.ToString("##") : Exit Sub
  31.             End If
  32.             Label1.Text &= " Risultato  " & f.ToString()
  33.  
  34.         Catch ex As Exception
  35.             MsgBox(ex.Message, MsgBoxStyle.Information)
  36.         End Try
  37.     End Sub
  38.  
  39. End Class



Guarda questo codice, è un piccolo esempio di utilizzo di pulsanti, variabili, textbox, label, funzioni, codice di
controllo, ed altro...




If ok Then GOTO Avanza else GOTO Inizia

PM Quote